package sin;

import java.util.concurrent.Callable;

public class SimpleCount implements SumCountable {
	public double sumcount(int nThreads, int n) {
		
		Callable<Double>[] tasks = TasksDisturber.getTasks(nThreads, n);
		CountThread[] threads = new CountThread[nThreads];
		
		for (int i=0; i<nThreads; i++) {
			threads[i] = new CountThread(tasks[i]);
			threads[i].start();
		}
		
		double sum=0;
		
		for (int i=0; i<nThreads; i++) {
			try {
				threads[i].join();
				sum+=threads[i].getResult();
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		}
		
		return sum;
	}
}
